package com.itwn.portal.service;

import com.itwn.portal.entity.Score;
import com.itwn.portal.mapper.ScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @author cx
 * @date 2022/3/1
 * @apiNote
 */
@Service
public class ScoreService {
    @Autowired
    ScoreMapper scoreMapper;

    @CacheEvict(value="score",keyGenerator = "myGenerateKey")
    public Double queryAvgById(Integer rid) {
        return this.scoreMapper.selectAvgById(rid);
    }


    public Double queryMyScore(int rid, int uid) {
        System.out.println(rid+"=-=-"+uid);
        return this.scoreMapper.selectMyScore(rid,uid);
    }

    @CacheEvict(value="score",keyGenerator = "myGenerateKey",allEntries = true)
    public int selectVoteNum(Integer rid) {
        return this.scoreMapper.selectVoteNum(rid);
    }

    @CacheEvict(value={"score"},keyGenerator = "myGenerateKey",allEntries = true)
    public void add(Score score) {
        this.scoreMapper.insert(score);
    }
}
